package BehavioralPattern.Command.Extend;

import java.util.ArrayList;
import java.util.List;

/**
 * 加入Log和排序
 * 
 * @author Xinz
 *
 * 遥控器
 */
public class Invoker {

	private List<Command> cmdList = new ArrayList<Command>();
	
	public Invoker() {
		
	}
	
	public void add(Command command) {
		cmdList.add(command);
	}
	
	public void remove(Command command) {
		cmdList.remove(command);
	}
	
	public void action() {
		Command cmd;
		while((cmd = getCmd()) != null) {
			System.out.println("Begin:" + cmd.getName());
			cmd.execute();
			System.out.println("End:" + cmd.getName());
		}
	}
	
	public Command getCmd() {
		// 可以按照自定义优先级，排序取出cmd
		return cmdList.remove(0);
	}
}
